package com.zmovie.admin.controller.movie;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zmovie.common.response.CommonReturnType;
import com.zmovie.framework.domain.MovieToType;
import com.zmovie.framework.service.MovieToTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 电影类型关联相关
 * @since 2023-12-02 10:29
 */
@Controller
@RequestMapping("/movie/movieToType")
@Api(tags = "电影类型关联相关")
public class MovieToTypeController {
    @Autowired
    private MovieToTypeService movieToTypeService;

    @PostMapping
    @ResponseBody
    @ApiOperation("给电影添加类型")
    public Object addTypeToMovie(@Validated MovieToType movieToType){
        movieToTypeService.save(movieToType);
        return CommonReturnType.success("添加成功!");
    }

    @DeleteMapping
    @ResponseBody
    @ApiOperation("删除电影绑定的类型")
    public Object deleteTypeForMovie(@Validated MovieToType movieToType){
        LambdaQueryWrapper<MovieToType> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MovieToType::getMovieId, movieToType.getMovieId());
        wrapper.eq(MovieToType::getTypeId, movieToType.getTypeId());
        movieToTypeService.remove(wrapper);
        return CommonReturnType.success("删除成功!");
    }
}
